package models;

import java.util.LinkedList;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;

import play.db.jpa.Model;

@Entity
public class Role extends Model { // Created by Tarek sheasha
    @ManyToOne
	private User user;
	private String        title;
	@ManyToOne
	private Organization  relatedOrganization;
	// Organization to which a user has this specific Role, Tarek Sheashaa
	@ManyToOne
	private Eentity relatedEntity;
	// Entity to which a user has this specific Role, Tarek Sheasha
	@ManyToOne
	private Topic         relatedTopic;
	// Topic to which a user has this specific Role, Ebtehal Abed
	@ManyToOne
	private Tag           relatedTag;
	// Tag to which a user has this specific Role, Ebtehal Abed
	@ManyToOne
	private Idea          relatedIdea; // Author nora @ 2011/4/28
	@ManyToOne
	private Comment       relatedComment; // Author nora @ 2011/4/28
	private boolean       canEdit;
	private boolean 	  canDelete;
	private boolean       canPost;
	private boolean       canInvite;
	private boolean       canTag;
	private boolean       canSpam ; 
	private boolean       canMerge ; //Author nora @2011/4/28
	//Enable user to create tag , Mostafa Badr
	//Ability of User to Lock/Unlock topics, Tarek Sheasha
	private boolean       canAdministerTopic;
	//Ability to create organisation and become its lead should be available to all Users,Tarek Sheasha
	private boolean       canCreateOrganisaition;
	private boolean       canBeRestricted;
	private boolean       canAdministerEntity;
	

	/**
	 * Constructor for Role where role entered as String and privileges are set
	 * to that user
	 * 
	 * @Author Tarek Sheasha
	 * @Version 24042011

	 * @param relatedOrganization
	 * @param relatedEntity
	 * @param role
	 */
	public Role(Organization relatedOrganization, String role) {

		this.relatedOrganization = relatedOrganization;
		this.relatedEntity = null;
		this.relatedTopic = null;
		this.setRelatedTag(null);
       
        
		if (role.equalsIgnoreCase("Lead")) {

			canEdit = true;
			canPost = true;
			canInvite = true;
			canDelete = true;
			canAdministerTopic = true;
			canCreateOrganisaition = true;
			canAdministerEntity = true;
			canSpam = true;
			canTag = true;
			canMerge = true;
			canBeRestricted = false;
			title = "Lead";
		} else {
			if (role.equalsIgnoreCase("Organizer")) {

				canEdit = true;
				canPost = true;
				canDelete = true;
				canCreateOrganisaition = false;
				canInvite = true;
				canAdministerTopic = true;
				canBeRestricted = true;
				canAdministerEntity = true;
				title = "Organizer";
			} else {
				if (role.equalsIgnoreCase("Follower")) {

					canPost = false;
					canBeRestricted = true;
					canCreateOrganisaition = false;
					canEdit = false;
					canInvite = false;
					canDelete = false;
					canAdministerTopic = false;
					canAdministerEntity = false;
					title = "Follower";
				} else {

					if (role.equalsIgnoreCase("Member"))

						canPost = true;
					canBeRestricted = true;
					canCreateOrganisaition = false;
					canEdit = false;
					canInvite = false;
					canDelete = false;
					canAdministerTopic = false;
					canAdministerEntity = false;
					title = "Ideas' Developer";
				}
			}
			
		}
		
	}
	
	public Role(Eentity relatedEntity, String role) {
		this.relatedEntity = relatedEntity;
		this.relatedOrganization = null;
		this.relatedTopic = null;
		this.setRelatedTag(null);
	
		if (role.equalsIgnoreCase("Creator")) {

			canEdit = true;
			canPost = true;
			canInvite = true;
			canDelete = true;
			canAdministerTopic = true;
			canCreateOrganisaition = true;
			canAdministerEntity = true;
			canBeRestricted = false;
			title = "Creator";
		} else {
			if (role.equalsIgnoreCase("Organizer")) {

				canEdit = true;
				canPost = true;
				canDelete = true;
				canCreateOrganisaition = false;
				canInvite = true;
				canAdministerTopic = true;
				canBeRestricted = true;
				canAdministerEntity = true;
				title = "Organizer";
			} else {
				if (role.equalsIgnoreCase("Follower")) {

					canPost = false;
					canBeRestricted = true;
					canCreateOrganisaition = false;
					canEdit = false;
					canInvite = false;
					canDelete = false;
					canAdministerTopic = false;
					canAdministerEntity = false;
					title = "Follower";
				} else {

					if (role.equalsIgnoreCase("Member"))

						canPost = true;
					canBeRestricted = true;
					canCreateOrganisaition = false;
					canEdit = false;
					canInvite = false;
					canDelete = false;
					canAdministerTopic = false;
					canAdministerEntity = false;
					title = "Member";
				}
			}
		}
		
	}
	
	/**
	 * Constructor for Role where role entered as String and privileges are set
	 * to that user
	 * 
	 * @Author Ebtehal Abed
	 * @Version 2042011

	 * @param relatedTag
	 * @param relatedTopic
	 * @param role
	 */
	public Role(Tag relatedTag, String role) {
		this.setRelatedTag(relatedTag);
		this.relatedEntity = null;
		this.relatedOrganization = null;
		this.relatedTopic = null;

		if (role.equalsIgnoreCase("Creator")) {

			canEdit = true;
			canPost = true;
			canInvite = true;
			canDelete = true;
			canAdministerTopic = true;
			canCreateOrganisaition = true;
			canAdministerEntity = true;
			canBeRestricted = false;
			title = "Creator";
		} else {
			if (role.equalsIgnoreCase("Organizer")) {

				canEdit = true;
				canPost = true;
				canDelete = true;
				canCreateOrganisaition = false;
				canInvite = true;
				canAdministerTopic = true;
				canBeRestricted = true;
				canAdministerEntity = true;
				title = "Organizer";
			} else {
				if (role.equalsIgnoreCase("Follower")) {

					canPost = false;
					canBeRestricted = true;
					canCreateOrganisaition = false;
					canEdit = false;
					canInvite = false;
					canDelete = false;
					canAdministerTopic = false;
					canAdministerEntity = false;
					title = "Follower";
				}
			}
		}
			
	}

	public Role(Topic relatedTopic, String role) {
		this.relatedTopic = relatedTopic;
		this.relatedOrganization = null;
		this.relatedEntity = null;
		this.setRelatedTag(null);
	
		if (role.equalsIgnoreCase("Creator")) {

			canEdit = true;
			canPost = true;
			canInvite = true;
			canDelete = true;
			canAdministerTopic = true;
			canCreateOrganisaition = true;
			canAdministerEntity = true;
			canBeRestricted = false;
			title = "Creator";
		} else {
			if (role.equalsIgnoreCase("Organizer")) {

				canEdit = true;
				canPost = true;
				canDelete = true;
				canCreateOrganisaition = false;
				canInvite = true;
				canAdministerTopic = true;
				canBeRestricted = true;
				canAdministerEntity = true;
				title = "Organizer";
			} else {
				if (role.equalsIgnoreCase("Follower")) {

					canPost = false;
					canBeRestricted = true;
					canCreateOrganisaition = false;
					canEdit = false;
					canInvite = false;
					canDelete = false;
					canAdministerTopic = false;
					canAdministerEntity = false;
					title = "Follower";
				} else {

					if (role.equalsIgnoreCase("Member"))

						canPost = true;
					canBeRestricted = true;
					canCreateOrganisaition = false;
					canEdit = false;
					canInvite = false;
					canDelete = false;
					canAdministerTopic = false;
					canAdministerEntity = false;
					title = "Member";
				}
			}
		}
		
	}

	/**
	 * Constructor for Role where role entered as String and privileges are set
	 * to that user
	 * 
	 * @Author Nora Zakhary
	 * @Version 29042011

	 * @param relatedIdea
	 * @param role
	 */
	public Role(Idea relatedIdea, String role) {
		 
		this.relatedIdea = relatedIdea;
		
	if (role.equalsIgnoreCase("Creator")) {
		canDelete				 = true;
		canMerge                 =false;
		title                    = "Creator";
	} else {
		if (role.equalsIgnoreCase("Follower")) {
			canDelete                = false;
			canMerge                 =false;
			title 					= "Follower";
		} 
		
	}
	
}
	/**
	 * Constructor for Role where role entered as String and privileges are set
	 * to that user
	 * 
	 * @Author Nora Zakhary
	 * @Version 29042011

	 * @param relatedComment
	 * @param role
	 */
public Role(Comment relatedComment, String role) {
	    
	    
		this.relatedComment = relatedComment;
		
		
	if (role.equalsIgnoreCase("Creator")) {
		canDelete				 = true;
		canEdit                =true;
		canSpam                 = false;
		title                    = "Creator";
	} else {
		if (role.equalsIgnoreCase("Follower")) {
			canDelete                = false;
			canEdit                 = false;
			canSpam                 = true;
			title 					= "Follower";
		} 
				
	}
	
}


	public boolean isCanEdit() {
		return canEdit;
	}

	public void setCanEdit(boolean canEdit) {
		this.canEdit = canEdit;
	}

	public boolean isCanDelete() {
		return canDelete;
	}


	public void setCanDelete(boolean canDelete) {
		this.canDelete = canDelete;
	}

	public boolean isCanPost() {
		return canPost;
	}

	public void setCanPost(boolean canPost) {
		this.canPost = canPost;
	}

	public boolean isCanInvite() {
		return canInvite;
	}

	public void setCanInvite(boolean canInvite) {
		this.canInvite = canInvite;
	}

	public boolean isCanAdministerTopic() {
		return canAdministerTopic;
	}

	public void setCanAdministerTopic(boolean canAdministerTopic) {
		this.canAdministerTopic = canAdministerTopic;
	}

	public boolean isCanCreateOrganisation() {
		return canCreateOrganisaition;
	}

	public void setCanCreateOrganisaition(boolean canCreateOrganisaition) {
		this.canCreateOrganisaition = canCreateOrganisaition;
	}

	public boolean isCanBeRestricted() {
		return canBeRestricted;
	}

	public void setCanBeRestricted(boolean canBeRestricted) {
		this.canBeRestricted = canBeRestricted;
	}

	public boolean isCanAdministerEntity() {
		return canAdministerEntity;
	}

	public void setCanAdministerEntity(boolean canAdministerEntity) {
		this.canAdministerEntity = canAdministerEntity;
	}

	public Organization getRelatedOrganization() {
		return relatedOrganization;
	}

	public void setRelatedOrganization(Organization relatedOrganization) {
		this.relatedOrganization = relatedOrganization;
	}

	public Eentity getRelatedEntity() {
		return relatedEntity;
	}

	public void setRelatedEntity(Eentity relatedEntity) {
		this.relatedEntity = relatedEntity;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setUsers(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}

	public void setUserCanTag(boolean canTag) {// mostafa badr
		this.canTag = canTag;
	}

	public boolean getUserCanTag() {// mostafa badr
		return canTag;
	}

	public void setRelatedTopic(Topic relatedTopic) {
		this.relatedTopic = relatedTopic;
	}

	public Topic getRelatedTopic() {
		return relatedTopic;
	}

	public void setRelatedTag(Tag relatedTag) {
		this.relatedTag = relatedTag;
	}

	public Tag getRelatedTag() {
		return relatedTag;
	}

	

	

	

	public Idea getRelatedIdea() {
		return relatedIdea;
	}

	public void setRelatedIdea(Idea relatedIdea) {
		this.relatedIdea = relatedIdea;
	}

	public Comment getRelatedComment() {
		return relatedComment;
	}

	public void setRelatedComment(Comment relatedComment) {
		this.relatedComment = relatedComment;
	}

	public boolean isCanSpam() {
		return canSpam;
	}

	public void setCanSpam(boolean canSpam) {
		this.canSpam = canSpam;
	}

	public boolean isCanMerge() {
		return canMerge;
	}

	public void setCanMerge(boolean canMerge) {
		this.canMerge = canMerge;
	}
}